package com.xyh.utils;

import com.xyh.entity.YxcCar;
import com.xyh.entity.YxcYhq;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class Util {

    public static void fillToCarList(List<YxcCar> carList,int num){
        int fillNum = num - carList.size();
        while (fillNum-- > 0){
            carList.add(null);
        }
    }

    /**
     * 获取当前时间
     */
    public static String getTimeNow(){
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        return formatter.format(date);
    }

    /**
     * 获取两个时间段相隔的小时数
     */
    public static int getDifferHour(String startTime, String endTime) {
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = null,endDate = null;
        try {
            startDate = formatter.parse(startTime);
            endDate = formatter.parse(endTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long dayM = 1000 * 24 * 60 * 60;
        long hourM = 1000 * 60 * 60;
        long differ = endDate.getTime() - startDate.getTime();
        long hour = differ % dayM / hourM + 24 * (differ / dayM);
        return Integer.parseInt(String.valueOf(hour));
    }

    /**
     * 计算所需缴纳费用
     */
    public static int getNeedPayNumber(int totalTime,int vipState){
        int num = vipState == 0 ? 5:3;
        return totalTime * num;
    }

    /**
     * 计算购买所需要的积分数
     */
    public static int getNumberOfBuy(List<YxcYhq> yhqList, int[] arr) {
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            res += arr[i] * yhqList.get(i).getGm_jifen();
        }
        return res;
    }
}
